<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<%
	String path = request.getContextPath();
	// 获得本项目的地址(例如: http://localhost:8080/MyApp/)赋值给basePath变量 
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	// 将 "项目路径basePath" 放入pageContext中，待以后用EL表达式读出。 
	pageContext.setAttribute("basePath", basePath);
	//out.write(basePath);
%>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>用户信息添加</title>

<meta name="description"
	content="Source code generated using layoutit.com">
<meta name="author" content="LayoutIt!">

<link href="<%=basePath%>bootstrap/css/bootstrap.min.css"
	rel="stylesheet">
<link href="<%=basePath%>bootstrap/css/style.css" rel="stylesheet">



<!--派生选择器设置提示信息的字体颜色-->
<style type="text/css">
div span {
	color: red;
}
</style>
<script src="<%=basePath%>bootstrap/js/jquery.min.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script src="<%=basePath%>bootstrap/js/scripts.js"></script>
<script type="text/javascript">
	//以下进行用户修改缓存以及表单验证
	$(function() {
		//*********************下拉选择框赋值****************************//
		console.info("age:" + $("#hiddenselectAge")[0].value);
		var currentAge = $("#hiddenselectAge")[0].value;
		//没有获取到年龄，或者后台没有传入年龄（新增操作）
		//$("#txtUserAge").val($("#hiddenselectAge")[0].value);
		// 设置下拉选择框的选中选项
		$("#inputUserAge").val(currentAge);

		//*********************性别单选框赋值*********************//
		//获取需要绑定事件的控件
		//使用模糊匹配选择器选择 所有的单选框对象，并使用each函数遍历每个单选框对象
		$("input[name^='inputUserSex']").each(function() {
			//给每一个单选框绑定一个自定义名为myOnload的事件
			$(this).bind("myOnload", function() {
				//自定义时间的处理业务
				//获取需要绑定的性别的隐藏属性值（el表达式获取服务器传来的值）
				var val = $("#hiddensex").get(0).value;
				//如果当前正在遍历的单选框的属性值等于服务器传过来的值
				if ($(this).attr("value") == val) {
					//绑定checked属性
					$(this)[0].checked = "checked";

				} else {
					$(this).removeAttr("checked");
				}
			});
			//触发该自定义的事件（自动执行）
			$(this).trigger("myOnload");
		});
	});

	//添加用户信息-表单验证
	//1.用户名非空验证
	function checkName() {
		//获取输入的内容
		var inputUserName = document.getElementById("inputUserName").value;
		//错误提示框信息内容
		var spUserName = document.getElementById("spUserName");
		if (inputUserName == null || inputUserName == "") {
			//提示信息
			spUserName.innerHTML = "请输入用户名！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserName.innerHTML = "";
			return true;
		}
	}
	//2.密码非空验证
	function checkPsw() {
		//获取输入的内容
		var inputPassword3 = document.getElementById("inputPassword3").value;
		//错误提示框信息内容
		var spUserPassword3 = document.getElementById("spUserPassword3");
		if (inputPassword3 == null || inputPassword3 == "") {
			//提示信息
			spUserPassword3.innerHTML = "请输入密码！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserPassword3.innerHTML = "";
			return true;
		}
	}
	/* //3.性别非空验证
	function checkSex() {
		//获取输入的内容
		var inputUserSex = document.getElementById("inputUserSex").value;
		//错误提示框信息内容
		var spUserUserSex = document.getElementById("spUserUserSex");
		if (inputUserSex == null || inputUserSex == "") {
			//提示信息
			spUserUserSex.innerHTML = "请输入性别！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserUserSex.innerHTML = "";
			return true;
		}
	}*/

	//3.性别非空验证
	function checkSex() {
		//获取输入的内容
		var inputUserSex = document.getElementsByName("inputUserSex");
		//设置标识量
		var chSex = false;
		for (var i = 0; i < inputUserSex.length; i++) {
			if (inputUserSex[i].checked) {
				chSex = true;
				break;
			}
		}
		//错误提示框信息内容
		var spUserUserSex = document.getElementById("spUserUserSex");
		if (!chSex) {
			//提示信息
			spUserUserSex.innerHTML = "请选择性别！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserUserSex.innerHTML = "";
			return true;
		}
	}
	//4.年龄非空验证
	function checkAge() {
		//获取输入的内容
		var inputUserAge = document.getElementById("inputUserAge").value;
		//错误提示框信息内容
		var spUserUserAge = document.getElementById("spUserUserAge");
		if (inputUserAge == null || inputUserAge == "") {
			//提示信息
			spUserUserAge.innerHTML = "请选择年龄！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserUserAge.innerHTML = "";
			return true;
		}
	}

	//5.联系方式非空验证
	function checkTel() {
		//获取输入的内容
		var inputUserTel = document.getElementById("inputUserTel").value;
		//错误提示框信息内容
		var spUserUserTel = document.getElementById("spUserUserTel");
		if (inputUserTel == null || inputUserTel == "") {
			//提示信息
			spUserUserTel.innerHTML = "请输入联系方式！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserUserTel.innerHTML = "";
			return true;
		}
	}
	//6.地址非空验证
	function checkAdress() {
		//获取输入的内容
		var inputUserAdress = document.getElementById("inputUserAdress").value;
		//错误提示框信息内容
		var spUserUserAdress = document.getElementById("spUserUserAdress");
		if (inputUserAdress == null || inputUserAdress == "") {
			//提示信息
			spUserUserAdress.innerHTML = "请输入地址！";
			//改变标志量
			return false;
		} else {
			//清空提示信息
			spUserUserAdress.innerHTML = "";
			return true;
		}
	}
	//进行最后的提交验证
	function checkAll() {
		var ischName = checkName();
		var ischPsw = checkPsw();
		var ischSex = checkSex();
		var ischAge = checkAge();
		var ischTel = checkTel();
		var ischAdre = checkAdress();
		if (ischName && ischPsw && ischSex && ischAge && ischTel && ischAdre) {
			return true;
		} else {
			return false;
		}
	}
</script>
</head>
<body>

	<div id="container" align="center">
		<div style="width: 500px;" align="left">
			<h4 align="center">添加/修改用户信息</h4>
			<form class="form-horizontal" role="form"
				action="<%=basePath%>InsertUserInfo" method="post">

				<input type="hidden" id="inputUserId" name="inputUserId"
					value="${requestScope.uBean.userid}"> <input type="hidden"
					id="hiddensex" value="${requestScope.uBean.usersex}"> <input
					type="hidden" id="hiddenselectAge"
					value="${requestScope.uBean.userage}">

				<div class="form-group">
					<label for="inputUserName" class="col-sm-2 control-label">用户名&nbsp;</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputUserName"
							name="inputUserName" value="${requestScope.uBean.username}"
							placeholder=用户名 onblur="checkName();">
						<div>
							<span id="spUserName"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">密&nbsp;&nbsp;&nbsp;码&nbsp;&nbsp;</label>
					<div class="col-sm-10">
						<input type="password" class="form-control" id="inputPassword3"
							name="inputPassword3" value="${requestScope.uBean.userpsw}"
							placeholder="密码" onblur="checkPsw();">
						<div>
							<span id="spUserPassword3"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="inputUserSex" class="col-sm-2 control-label">性&nbsp;&nbsp;&nbsp;别&nbsp;&nbsp;</label>
					<div class="col-sm-10">
						<!--  <input type="text" class="form-control" id="inputUserSex"
							name="inputUserSex" value="${requestScope.uBean.usersex}"
							placeholder=性别 onclick="checkSex();">-->
						<label class="radio-inline"> <input type="radio"
							name="inputUserSex" id="selectSex1" value="男"
							onclick="checkSex();"> 男
						</label> <label class="radio-inline"> <input type="radio"
							name="inputUserSex" id="selectSex2" value="女"
							onclick="checkSex();"> 女
						</label>
						<!--  <label class="radio-inline"> <input type="radio"
							name="inputUserSex" id="inputUserSex1" value="男"
							<c:if test="${requestScope.uBean.usersex=='男'}">checked</c:if>>男
						</label> <label class="radio-inline"> <input type="radio"
							name="inputUserSex" id="inputUserSex2" value="女"
							<c:if test="${requestScope.uBean.usersex=='女'}">checked</c:if>>女
						</label>-->
						<div>
							<span id="spUserUserSex"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="inputUserAge" class="col-sm-2 control-label">年&nbsp;&nbsp;&nbsp;龄&nbsp;&nbsp;</label>
					<div class="col-sm-10">
						<!--<input type="text" class="form-control" id="inputUserAge"
							name="inputUserAge" value="${requestScope.uBean.userage}"
							placeholder=年龄 onblur="checkAge();">-->
						<select class="form-control" id="inputUserAge" name="inputUserAge"
							onclick="checkAge();">
							<option value=""></option>
							<c:forEach begin="18" end="60" varStatus="vst">
								<option value="${vst.index}">${vst.index}</option>
							</c:forEach>
						</select>
						<div>
							<span id="spUserUserAge"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="inputUserTel" class="col-sm-2 control-label">联系方式</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputUserTel"
							name="inputUserTel" value="${requestScope.uBean.usertel}"
							placeholder=联系方式 onblur="checkTel();">
						<div>
							<span id="spUserUserTel"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label for="inputUserAdress" class="col-sm-2 control-label">地&nbsp;&nbsp;&nbsp;址&nbsp;&nbsp;</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="inputUserAdress"
							name="inputUserAdress" value="${requestScope.uBean.useraddress}"
							placeholder=地址 onblur="checkAdress();">
						<div>
							<span id="spUserUserAdress"></span>
						</div>
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-default"
							onclick="return checkAll();">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>



</body>
</html>